package com.crm.system.controller.customerManager;

import cn.hutool.http.HttpException;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.common.util.CommonUtils;
import com.crm.model.entity.cluePoolManager.ClueVisitRecord;
import com.crm.model.entity.contactManager.Contact;
import com.crm.model.entity.customerManager.*;
import com.crm.model.entity.orderManager.CustomerProductOrder;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.qo.customerManager.CustomerAddQO;
import com.crm.model.qo.customerManager.CustomerAnalysisRequestQo;
import com.crm.model.qo.customerManager.CustomerQO;
import com.crm.model.qo.customerManager.MoveCustomerQO;
import com.crm.model.vo.cluePoolManager.ClueFollowVO;
import com.crm.model.vo.contactManager.ContactMyVO;
import com.crm.model.vo.contactManager.IndustryAreaVO;
import com.crm.model.vo.customerContractManager.CustomerContractVO;
import com.crm.model.vo.customerContractManager.exchangeVO;
import com.crm.model.vo.customerManager.*;
import com.crm.model.vo.finishOrderProduct.FinishOrderProductVO;
import com.crm.model.vo.opportunityManager.OpportunityCustomerVO;
import com.crm.model.vo.orderManager.CustomerProductOrderVO;
import com.crm.model.vo.returnMoney.CustFinanceProductOderVO;
import com.crm.redis.service.customerManager.CustomerRedisService;
import com.crm.system.service.contactManager.ContactService;
import com.crm.system.service.customerManager.CustomerContactPersonService;
import com.crm.system.service.customerManager.CustomerService;
import com.crm.system.service.customerManager.CustomerTagService;
import com.crm.system.service.orderManager.CustomerProductOrderService;
import com.crm.system.service.returnMoney.ReturnMoneyService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ Author ：pym
 * @ Date   ：2021/1/18 15:53
 */
@RestController
@RequestMapping("/customerTagsController")
@Slf4j
public class CustomerTagController {


    @Autowired
    CustomerTagService customerTagService;

    /**
     * 管理模块 -- 客户列表
     *
     * @return
     */
    @PostMapping("/tagList")
    public DataResponse customerPoolList(HttpServletRequest request,
                                         @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                         @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                         @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                         @RequestParam(value = "sortOrder", required = false) String sortOrder//排序规则(asc/desc)
    ) {
        try {
            DhPageInfo<ChsCustomerTag> customerVOList = customerTagService.selectCustomerTagList(pageIndex, pageSize, sortName, sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), customerVOList);
        } catch (Exception e) {
            log.error("customerTagsController tagList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    @PostMapping("/addTag")
    public DataResponse addCompetitor(@RequestBody ChsCustomerTag chsCustomerTag) {
        if(customerTagService.selectTagNameSize(chsCustomerTag) > 0){
            return new DhResponse(ResponseCodeEnum.CUSTOMER_TAG_EXCEED.getResponseCode());
        };
        if(customerTagService.selectTagSize(chsCustomerTag) >= 10){
            return new DhResponse(ResponseCodeEnum.CUSTOMER_TAG_MORE.getResponseCode());
        };
        Boolean result = customerTagService.addTag(chsCustomerTag);
        if (result) {
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } else {
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    @PostMapping("/deleteTag")
    public DataResponse deleteTag(@RequestParam(value = "id", required = true) String id) {
        try {
            Boolean result = customerTagService.deleteCustomerTagById(id);
            if (result) {
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("customerController deleteCustomer error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }
}
